define(function(require) {

    'use strict';

    var Backbone = require('backbone'),
        Base = require('components/pop/base'),
        template = require('text!components/pop/templates/apps_qrcode.html'),
        utils = require('core/utils'),
        _ = require('underscore');

    return Base.extend({

        template: _.template(template),

        className: function() {
            return this.options.className;
        },

        initialize: function(options) {
            this.data = options.data;
            Base.prototype.initialize.call(this, options);
        },

        events: {
            'click .js-close': 'hide'
        },

        isShow: function() {
            var display = this.$el.css('display');
            return display === 'none' ? false : true;
        },

        positioning: function() {
            var view = this;
            var className = view.options.className;

            view.$el.show();

            utils.focus(view.$('.js-btn-confirm'));

            if (className.indexOf('left') !== -1) {
                view.$el.position({
                    of: view.target,
                    my: 'right center',
                    at: 'left center',
                    collision: 'none'
                });
            } else if(className.indexOf('bottom') !== -1) {
                view.$el.position({
                    of: view.target,
                    my: 'center top',
                    at: 'center bottom',
                    collision: 'none'
                });
            } else {
                view.$el.position({
                    of: view.target,
                    my: 'left center',
                    at: 'right center',
                    collision: 'none'
                });
            }

            view.el.className = view.options.className;
        },

        render: function() {
            var that = this;
            that.$el.html(that.template(that.data));
            that.el.className = that.options.className;
            return that;
        },

        reset: function(obj) {
            var callback = obj.callback,
                target = obj.target,
                trigger = obj.trigger,
                className = obj.className || 'popover left';

            this.options.className = className;
            this.setCallback(callback);
            this.setTarget(target);
            this.setTrigger(trigger);
            this.positioning();
            this.show();
        }
    });
});
